﻿-- Function: tepuy.modules()

-- DROP FUNCTION tepuy.modules();

CREATE OR REPLACE FUNCTION tepuy.modules()
  RETURNS SETOF tepuy.base_modules AS
$BODY$
-- Copyright © 2010 Riztan Gutierrez <riztan at gmail dot com>
-- Esto es parte de: proyecto tepuy.
-- Este programa es Software Libre conforme a la GPL Version 3 o posterior.
-- http://www.gnu.org/licenses/
DECLARE
    r tepuy.base_modules%rowtype;
    module record;
BEGIN
    FOR module IN select table_schema from information_schema.tables 
	                  where table_catalog='tepuy' and table_name='base_modules'
       LOOP	                  

       FOR r IN execute 'SELECT * FROM ' || module.table_schema || '.base_modules'
	   LOOP
           RETURN NEXT r; -- retorna actual linea del SELECT
       END LOOP;
    END LOOP;
    RETURN;
END
$BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION tepuy.modules() OWNER TO postgres;
COMMENT ON FUNCTION tepuy.modules() IS 
        'retorna modulos existentes para tepuy';
